
<template>
  <div>
    <div style="height:30px">
      <el-breadcrumb
        separator-class="el-icon-arrow-right">
        <el-breadcrumb-item
          :to="{ path: '/' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>业务板块</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <el-card shadow="never"
      class="mb20">
      <el-row :gutter="20">
        <el-form ref="form"
          :model="queryParam"
          label-width="100px">
          <el-col :lg="8">
            <el-form-item
              label="分类"
              class="mb0">
              <el-select
                v-model="queryParam.id"
                style="width:100%"
                placeholder="请输入栏目名称">
                <el-option
                  v-for="(item,index) in list"
                  :key="index"
                  :label="item.name"
                  :value="item.id" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :lg="8">
            <el-button
              type="primary"
              @click="getTableList()">搜索</el-button>
            <el-button
              @click="reset()">重置</el-button>
          </el-col>
        </el-form>
      </el-row>
    </el-card>
    <el-card shadow="never">
      <div
        style="margin-bottom:20px">
        <!-- <el-button
          type="primary"
          @click="$emit('go',{view:'ActiveDetail',info:{}})">新增业务</el-button> -->
        <el-button
          type="primary"
          @click="$refs.show.open('add',list,{},pageArr)">新增业务</el-button>
        <!--  -->
      </div>
      <el-row
        v-if="tableDate.length > 0"
        :gutter="20">
        <el-col
          v-for="(item,index) in tableDate"
          :key="index" :lg="6"
          :md="8" :sm="12">
          <el-card
            class="mb20 card"
            :body-style="{ padding: '0px' }">
            <span class="tag"
              :style="{background:item.isEnable === 0 ?'#67c23a':'red'}">{{ item.isEnableName }}</span>
            <el-popover
              placement="right"
              width="420"
              trigger="hover">
              <img
                class="card_img"
                :src="item.imagesUrl">
              <img
                slot="reference"
                class="card_img"
                :src="item.imagesUrl">
            </el-popover>
            <div
              class="card_body">
              <div>
                <span
                  class="card_title">项目名称：</span>
                <span
                  class="line-1"
                  style="width: calc(100% - 100px);">
                  {{ item.name }}
                </span>
              </div>
              <div>
                <span
                  class="card_title">项目分类：</span>
                <span
                  class="line-1"
                  style="width: calc(100% - 100px);">
                  {{ item.projectName }}
                </span>
              </div>
              <div>
                <span
                  class="card_title">项目详情：</span>
                <span
                  class="line-2"
                  style="width: calc(100% - 100px);"
                  v-html="item.content" />
              </div>
            </div>
            <div
              class="bottom card_footer">
              <span
                class="blue_text"
                style="border-right:1px solid #d9d9d9"
                @click="editTable(item)">编辑</span>
              <span
                class="red_text"
                @click="showDel(item)">删除</span>
            </div>
          </el-card>
        </el-col>
      </el-row>
      <div v-else>
        <el-empty
          description="暂无数据" />
      </div>
      <div
        style="margin-top: 33px">
        <el-pagination
          :current-page="pageNum"
          :page-sizes="[12, 24, 36, 48]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange" />
      </div>
      <ModalView ref="show"
        @ok="getTableList" />
    </el-card>
  </div>
</template>

<script>
import { REQUEST_LIST } from '@/api/requestList'
import ModalView from './modal.vue'
export default {
  name: 'ActiveList',
  components: {
    ModalView
  },
  data() {
    return {
      pageNum: 1,
      pageSize: 12,
      total: 0,
      tagType: '',
      list: [],
      tableLoading: false,
      queryParam: {
        id: ''
      },
      tableDate: [],
      pageArr: []
    }
  },
  mounted() {
    this.getInit()
  },
  methods: {
    search() {
      this.getTableList()
    },
    getInit() {
      REQUEST_LIST.REQUST_FCN('RESOURCESINIT', {}).then(res => {
        // this.list = res.data.projectList
        this.list = res.data.projectList.filter(item => {
          if (item.name) {
            return item.name.includes('业务板块')
          }
        })
      })

      REQUEST_LIST.REQUST_FCN('INITLANMU', {}).then(res => {
        // this.list =
        this.pageArr = res.data.projectList.filter(item => {
          return item.name.includes('业务板块')
        })
        this.getTableList()
      })
    },
    /**
     * @description: 获取数据列表
     * @param {type}
     * @return:
     */
    getTableList() {
      this.tableLoading = true
      REQUEST_LIST.REQUST_FCN(
        'RESOURCESLIST',
        {
          pageNum: this.pageNum,
          pageSize: this.pageSize,
          projectParentId: this.pageArr[0].id,
          projectId: this.queryParam.id
        },
        true
      ).then(res => {
        this.tableDate = res.data.resourcesList
        this.tableDate.map(item => {
          this.$set(item, 'imagesUrl', res.data.imgUrl + '/' + item.url)
        })
        console.log(this.tableDate, 'this.tableDate')
        this.total = parseInt(res.data.total)
        this.tableLoading = false
      })
    },
    /**
     * @description: 重置
     * @param {type}
     * @return:
     */
    reset() {
      this.pageNum = 1
      this.queryParam.id = ''
      this.getTableList()
    },
    /**
     * @description: 翻页函数
     * @page {number}
     * @pageSize {number}
     * @return:
     */
    handleSizeChange(e) {
      this.pageSize = e
      this.getTableList()
    },
    handleCurrentChange(e) {
      this.pageNum = e
      this.getTableList()
    },
    showDel(e) {
      this.$confirm('确认删除吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          REQUEST_LIST.REQUST_FCN('RESOURCESDEL', { id: e.id }, true).then(res => {
            this.$message.success('删除成功！')
            this.getTableList()
          })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
    },
    editTable(e) {
      this.$refs.show.open('edit', this.list, e, this.pageArr)
    }
  }
}
</script>
<style scoped>
.card_img {
  height: 160px !important;
  width: 100%;
  cursor: pointer;
}
.card {
  position: relative;
}
.card .tag {
  position: absolute;
  display: inline-block;
  right: -25px;
  top: -10px;
  padding: 20px 20px 5px;
  transform: rotate(45deg);
  color: #fff;
}
.card .card_body {
  padding: 14px 14px 0;
  height: 150px;
  overflow: hidden;
}
.card .card_body div {
  display: flex;
  margin-bottom: 10px !important;
  align-items: flex-start;
}
.card .card_body div .card_title {
  width: 80px;
}
.line-1 {
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  max-height: 21px;
}
.line-2 {
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  /* height: 4px; */
  -webkit-box-orient: vertical;
  margin-top: 0px;
}
.card .card_footer {
  display: flex;
  width: 100%;
  border-top: 1px solid #e6e6e6;
  margin-top: 10px;
  padding: 15px 0;
}
.card .card_footer span {
  display: block;
  width: 100%;
  text-align: center;
  cursor: pointer;
}
.blue_text {
  color: #409eff;
}
.red_text {
  color: red;
}
</style>
